define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'work/service/index' + location.search,
                   /* add_url: 'work/service/add',
                    edit_url: 'work/service/edit',
                    del_url: 'work/service/del',
                    multi_url: 'work/service/multi',
                    import_url: 'work/service/import',*/
                    table: 'work_service',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                /*fixedColumns: true,
                fixedRightNumber: 1,*/
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'warranty_id', title: __('Warranty_id')},
                        {field: 'warranty.workID', title: __('Warranty.workID'), operate: 'LIKE'},
                        {field: 'type_data', title: __('Type_data'), searchList: {"0":__('Type_data 0'),"1":__('Type_data 1')}, formatter: Table.api.formatter.normal},
                        {field: 'servicetime', title: __('Servicetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'applytime', title: __('Applytime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'statementtime', title: __('Statementtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'contract_status', title: __('Contract_status'),
                            searchList: {" ":__('--'),"0":__('Contract_status 0'),"1":__('Contract_status 1'),"2":__('Contract_status 2')},
                            formatter: Table.api.formatter.status},
                        {field: 'service_type', title: __('Service_type'), searchList: {"0":__('Service_type 0'),"1":__('Service_type 1'),"2":__('Service_type 2')}, formatter: Table.api.formatter.normal},
                        //{field: 'user_id', title: __('User_id')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'warranty_time', title: __('Warranty_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'present_time', title: __('Present_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        /*{field: 'warranty.product', title: __('Warranty.product'), operate: 'LIKE'},
                        {field: 'warranty.device', title: __('Warranty.device'), operate: 'LIKE'},*/
                        {field: 'a.name', title: __('Warranty.product'), operate: 'LIKE'},
                        {field: 'a.marking', title: __('Warranty.device'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons: [
                                {
                                    name: 'see',
                                    title: __('详情'),
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    text: __('详情'),   icon: '',
                                    url: 'work/service/see'
                                },
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            table.bootstrapTable('hideColumn','warranty_id');
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
